﻿//全局处理
/*
window.onerror = function(errorMessage, scriptURL, lineNumber) {
    if (Ext) {
        Ext.net.DirectMethods.RegJsExceptInfo(errorMessage, scriptURL, lineNumber);
    } else {
        alert(errorMessage);
    }
}
*/

//页面Ajax异常处理
function AjaxReqExceptHandle(a, b) {
    if (b.errorMessage) {
        Ext.net.DirectMethods.RegAjaxExcptInfo(b.errorMessage);
    } else {
        Ext.net.DirectMethods.RegAjaxExcptInfo("未知错误");
    }
    return false;
}

//DirectEvent Failed处理
function DirectEventFailedHandle(response, errorMsg) {
    Ext.net.DirectMethods.RegAjaxExcptInfo(errorMsg);
}

//焦点绑定到控件
var focusObj = null;
function FocusEL() {
    if (focusObj != null) {
        focusObj.focus();
    }
}

//调转回登录页
function Rederict() {
    var p = this;
    while (p.parent != undefined && p.parent != null && p.name != "") {
        p = p.parent;
    }
    p.location.href = GetWebUrl() + "/login.aspx";
}

///<reference path="vswd-ext_2.2.js" />
//增加页面回车按键处理
function keyDown() {
    try {
        var keycode = event.keyCode;
        var keyChar = String.fromCharCode(keycode);
        if (keycode == 13) {
            if (document.activeElement.nodeName == "BUTTON")
                return true;
            if (Ext.getCmp(document.activeElement.id) != "undefined") {
                if (Ext.getCmp(document.activeElement.id).tabTip == "code") {
                    Ext.net.DirectMethods.TextKeyPress();
                    return false;
                }
                if (Ext.getCmp(document.activeElement.id).tabTip == "codex") {
                    Ext.net.DirectMethods.TextKeyPress(document.activeElement.id);
                    return false;
                }
            }
            event.keyCode = 9;
        } else if (event.keyCode == 8) {
            //使页面按BackSpace键时不触发浏览器后退事件
            if (event.srcElement.type == 'textarea' || event.srcElement.type == 'text' || event.srcElement.type == 'password') {
                if (event.srcElement.readOnly || event.srcElement.disabled) {
                    if (event.preventDefault) {
                        event.preventDefault();
                    } else {
                        event.returnValue = false;
                    }
                }
            } else {
                if (event.preventDefault) {
                    event.preventDefault();
                } else {
                    event.returnValue = false;
                }
            }
        }
    } catch (e) {

    }
};

document.onkeydown = keyDown;

//功能:此脚本函数适用于Manage列表页面中的 "增加/修改"按钮单击时,使链接的页面以Tab标签的形式显示在FirstPage页面的TabPanel上

//参数说明:tabPanel,页面上的tabPanel的id(我们常用首页面的TabPanel);id,定义链接页面的一个ID;url,链接页面的路径;title,标签的标题名称(可自己命名)
function addTab(tabPanel, id, url, title) {
    Ext.useShims = true;
    var tab = tabPanel.getComponent(id);
    if (!tab) {
        var newurl = "";
        if (url.indexOf('?') > 0)
            newurl = url + "&tabid=" + id;
        else
            newurl = url + "?tabid=" + id;
        tab = tabPanel.insert(tabPanel.items.keys.indexOf(tabPanel.activeTab.id) + 1, {
            id: id,
            title: title,
            closable: true,
            autoLoad: {
                showMask: true,
                url: newurl,
                mode: 'iframe',
                maskMsg: '载入中...'
            }
        });
    } else {
        var newurl = "";
        if (url.indexOf('?') > 0)
            newurl = url + "&tabid=" + id;
        else
            newurl = url + "?tabid=" + id;

        tab.loadContent(newurl);

    }
    tabPanel.setActiveTab(tab);

}

//关闭标签页面的函数,使用方法:在需要取消或关闭页面的按钮中直接调用此方法即可.
function closeTab() {
    var tabPanel = parent.ExampleTabs;
    var tab = tabPanel.getActiveTab();
    tabPanel.closeTab(tab, 'close');
}

function closeCurrTab() {
    Ext.net.DirectMethods.GetParentTabId(
      {
          success: function(result) { UpdateParent(result); closeTab(); }
      });
}
function clrTab() {
    Ext.net.DirectMethods.GetParentTabId(
      {
          success: function(result) { UpdateParent(result); }
      });
}

function UpdateParent(tabid) {
    var Param = tabid.split(",");
    if (parent.window.ExampleTabs.items.map[Param[0]] != null) {
        parent.window.ExampleTabs.items.map[Param[0]].iframe.dom.contentWindow[Param[1]].reload();
    }
}

//*************************************************以下公共调用页面弹出、双击***************************************************/
//********AddTab方式加载新页面(无自动过滤条件)
//********参数说明：flag(1,新增；2,修改按钮进入；3，双击进入);StringName(QueryString 名);StringField(QueryString 字段)
//********StringName和StringField必须一一对应,RowId只在双击grid时使用


function popfortab(GridName, Url, StringName, StringField, RowId, AttQryStr, TabId, TabName, flag) {
    if (flag == 2) {
        if (!GridName.hasSelection()) {
            Ext.Msg.alert("提示", "请选择记录!");
            return;
        }
        var record = GridName.selModel.getSelected();
    }
    var Str = "ptabid=" + TabId;
    var curTab = TabId + "_cur";
    var TabStr = TabId;
    var StrName = StringName.split(",");
    var StrField = StringField.split(",");
    if (flag == 1) {
        for (i = 0; i < StrName.length; i++) {
            Str += "&";
            Str = Str + StrName[i] + "=" + escape(StrField[i]); //wtw修改  20100507  
            if (StrName[i] != "WORK_STATE")
                TabStr += StrField[i];
        }
    }
    if (flag == 2) {
        for (i = 0; i < StrName.length; i++) {
            Str += "&";
            Str = Str + StrName[i] + "=" + escape(record.get(StrField[i]));  //wtw修改  20100507 
            if (StrName[i] != "WORK_STATE")
                TabStr += StrField[i];
        }
    }
    if (flag == 3) {
        var record3 = GridName.store.data.items[RowId].data;
        for (i = 0; i < StrName.length; i++) {
            Str += "&";
            Str = Str + StrName[i] + "=" + escape(record3[StrField[i]]);   //wtw修改  20100507  
            if (StrName[i] != "WORK_STATE")
                TabStr += StrField[i];
        }
    }

    var NewUrl = Url;
    if (Str != "") {
        if (NewUrl.indexOf('?') <= 0)
            NewUrl = NewUrl + "?" + Str; //定义菜单没有参数时

        else
            NewUrl = NewUrl + "&" + Str; //定义菜单有参数时
        if (AttQryStr != "")
            NewUrl = NewUrl + "&" + AttQryStr;
    }
    var tname = parent.ExampleTabs.getComponent(TabId);
    if (tname != null) {
        TabName = tname.title + '（详细）';
        var flag = "&";
        if (tname.autoLoad["url"].indexOf('readonly=1') > 0)
            NewUrl = NewUrl + flag + "readonly=1";
        else
            NewUrl = NewUrl + flag + "readonly=0";
    }

    addTab(parent.ExampleTabs, curTab, NewUrl, TabName);
}

function popfortab_page(Url, StringName, StringField, AttQryStr, TabId, TabName) {
    var Str = "ptabid=" + TabId;
    var curTab = TabId + "_cur";
    var TabStr = TabId;
    var StrName = StringName.split(",");
    var StrField = StringField.split(",");

    for (i = 0; i < StrName.length; i++) {
        Str += "&";
        Str = Str + StrName[i] + "=" + escape(StrField[i]); //wtw修改  20100507  
        if (StrName[i] != "WORK_STATE")
            TabStr += StrField[i];
    }

    var NewUrl = Url;
    if (Str != "") {
        if (NewUrl.indexOf('?') <= 0)
            NewUrl = NewUrl + "?" + Str; //定义菜单没有参数时

        else
            NewUrl = NewUrl + "&" + Str; //定义菜单有参数时
        if (AttQryStr != "")
            NewUrl = NewUrl + "&" + AttQryStr;
    }
    var tname = parent.ExampleTabs.getComponent(TabId);
    if (tname != null) {
        TabName = tname.title + '(' + TabName + ')';
        var flag = "&";
        if (tname.autoLoad["url"].indexOf('readonly=1') > 0)
            NewUrl = NewUrl + flag + "readonly=1";
        else
            NewUrl = NewUrl + flag + "readonly=0";
    }

    addTab(parent.ExampleTabs, curTab, NewUrl, TabName);
}

function addTabForSinger(Combo, Url, StringName, TabId) {
    var Str = StringName;
    if (StringName != "")
        Str = Str + "=" + Combo.getValue();
    Str = Str.replace('&', '');
    var NewUrl = Url;
    if (Str != "")
        NewUrl += "?" + Str;
    var tname = parent.ExampleTabs.getComponent(TabId);
    if (tname != null) {
        TabName = tname.title + '（详细）';
        var flag = "&";
        if (tname.autoLoad["url"].indexOf('readonly=1') > 0)
            NewUrl = NewUrl + flag + "readonly=1";
        else
            NewUrl = NewUrl + flag + "readonly=0";
    }
    addTab(parent.ExampleTabs, TabId + Str, NewUrl, TabName);

}



//***************************弹出窗口****************************


function popwin(url, title, width, height) {
    Ext.useShims = true;
    var newurl = url;
    var flag = "&";
    if (url.indexOf('?') <= 0)
        flag = "?";
    if (location.href.indexOf("readonly=1") > 0)
        newurl = newurl + flag + "readonly=1";
    else
        newurl = newurl + flag + "readonly=0";


    win = new Ext.Window({
        id: 'popwingy',
        title: "&nbsp;<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'auto',
        width: width,
        //        autoHeight:true,
        height: height,
        // autoShow:true,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        //        autoLoad: 
        //            { 
        //                showMask: true, 
        //                mode: 'iframe', 
        //              //  mode: 'remote', 
        //                noCache: false 
        //            }, 
        //contentEl : Ext.DomHelper.append(document.body, {
        //    showMask: true, 
        //    tag : 'iframe',
        //    style : "border 0px none;scrollbar:true",
        //    src : url,
        //    height : "100%",
        //    width : "100%"
        //   }),
        resizable: true,
        html: '<iframe  frameborder="0" width="100%" height="100%" src="' + newurl + '"></iframe>'

    });

    //    win.addListener('beforeshow', function(o) {
    //        o.height = 800;
    ////        alert(o.getHeight());
    //    });
    //win.on( 
    //"beforedestroy", 
    //function(obj){ 
    //Ext.Msg.alert("哈哈","你关不掉了吧！"); 
    //obj.show(); 
    //return false; 
    //popWin_beforedestroy();
    //} 
    //);
    win.show();
    // win.load(url);
}

//弹出顶层窗口，保存要刷新的对象到窗口
function popTopwin(url, title, width, height, inObject) {
    Ext.useShims = true;
    var newurl = url;
    var flag = "&";
    if (url.indexOf('?') <= 0)
        flag = "?";
    if (location.href.indexOf("readonly=1") > 0)
        newurl = newurl + flag + "readonly=1";
    else
        newurl = newurl + flag + "readonly=0";

    var p = this.parent;
    while (p.parent != undefined && p.parent != null && p.name != "") {
        p = p.parent;
    }

    win = new p.Ext.Window({
        id: 'popwingy',
        title: "<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'fit',
        width: width,
        height: height,
        // autoShow:true,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        resizable: false,
        autoLoad: {
            showMask: true,
            url: newurl,
            mode: 'iframe',
            maskMsg: '载入中...'
        }
        //        html: '<iframe frameborder="0" width="100%" height="' + height + '" src="' + newurl + '"></iframe>'
    });
    win.gobj = inObject;
    win.show();
}

function popTopwinWithId(id, url, title, width, height, inObject) {
    Ext.useShims = true;
    var newurl = url;
    var flag = "&";
    if (url.indexOf('?') <= 0)
        flag = "?";
    if (location.href.indexOf("readonly=1") > 0)
        newurl = newurl + flag + "readonly=1";
    else
        newurl = newurl + flag + "readonly=0";

    var p = this.parent;
    while (p.parent != undefined && p.parent != null && p.name != "") {
        p = p.parent;
    }

    win = new p.Ext.Window({
        id: id,
        title: "<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'fit',
        width: width,
        height: height,
        // autoShow:true,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        resizable: false,
        autoLoad: {
            showMask: true,
            url: newurl,
            mode: 'iframe',
            maskMsg: '载入中...'
        }
        //        html: '<iframe frameborder="0" width="100%" height="' + height + '" src="' + newurl + '"></iframe>'
    });
    win.gobj = inObject;
    win.show();
}
function popTopwinWithMax(id, url, title, width, height, isMax, inObject) {
    Ext.useShims = true;
    var newurl = url;
    var flag = "&";
    if (url.indexOf('?') <= 0)
        flag = "?";
    if (location.href.indexOf("readonly=1") > 0)
        newurl = newurl + flag + "readonly=1";
    else
        newurl = newurl + flag + "readonly=0";

    var p = this.parent;
    while (p.parent != undefined && p.parent != null && p.name != "") {
        p = p.parent;
    }

    win = new p.Ext.Window({
        id: id,
        title: "<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'fit',
        width: width,
        height: height,
        maximizable: true,
        maximized: isMax,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        resizable: true,
        autoLoad: {
            showMask: true,
            url: newurl,
            mode: 'iframe',
            maskMsg: '载入中...'
        }
        //        html: '<iframe frameborder="0" width="100%" height="' + height + '" src="' + newurl + '"></iframe>'
    });
    win.gobj = inObject;
    win.show();
}

function popwinForParent(url, title, width, height) {
    Ext.useShims = true;
    var newurl = url;
    var flag = "&";
    if (url.indexOf('?') <= 0)
        flag = "?";
    if (location.href.indexOf("readonly=1") > 0)
        newurl = newurl + flag + "readonly=1";
    else
        newurl = newurl + flag + "readonly=0";
    win = new parent.Ext.Window({
        id: 'popwingy',
        title: "<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'fit',
        width: width,
        height: height,
        // autoShow:true,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        //        autoLoad: 
        //            { 
        //                showMask: true, 
        //                mode: 'iframe', 
        //              //  mode: 'remote', 
        //                noCache: false 
        //            }, 
        //contentEl : Ext.DomHelper.append(document.body, {
        //    showMask: true, 
        //    tag : 'iframe',
        //    style : "border 0px none;scrollbar:true",
        //    src : url,
        //    height : "100%",
        //    width : "100%"
        //   }),

        resizable: false,
        html: '<iframe frameborder="0" width="100%" height="' + (height - 33) + '" src="' + newurl + '"></iframe>'  //减去的33px是 Ext.Window边框、标头所占的高度
    });
    win.show();
    // win.load(url);
}

//父窗体的上一级窗体的上一级窗体弹出
function popwinForParent3(winid, url, title, width, height) {
    Ext.useShims = true;
    var newurl = url;
    var flag = "&";
    if (url.indexOf('?') <= 0)
        flag = "?";
    if (location.href.indexOf("readonly=1") > 0)
        newurl = newurl + flag + "readonly=1";
    else
        newurl = newurl + flag + "readonly=0";
    win = new parent.parent.Ext.Window({
        id: winid,
        title: "<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'fit',
        width: width,
        height: height,
        // autoShow:true,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        //        autoLoad: 
        //            { 
        //                showMask: true, 
        //                mode: 'iframe', 
        //              //  mode: 'remote', 
        //                noCache: false 
        //            }, 
        //contentEl : Ext.DomHelper.append(document.body, {
        //    showMask: true, 
        //    tag : 'iframe',
        //    style : "border 0px none;scrollbar:true",
        //    src : url,
        //    height : "100%",
        //    width : "100%"
        //   }),

        resizable: false,
        html: '<iframe frameborder="0" width="100%" height="' + height + '" src="' + newurl + '"></iframe>'
    });
    win.show();
    // win.load(url);
}

//父窗体的上一级窗体弹出
function popwinForParent2(winid, url, title, width, height) {
    Ext.useShims = true;
    var newurl = url;
    var flag = "&";
    if (url.indexOf('?') <= 0)
        flag = "?";
    if (location.href.indexOf("readonly=1") > 0)
        newurl = newurl + flag + "readonly=1";
    else
        newurl = newurl + flag + "readonly=0";
    win = new parent.Ext.Window({
        id: winid,
        title: "<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'fit',
        width: width,
        height: height,
        // autoShow:true,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        //        autoLoad: 
        //            { 
        //                showMask: true, 
        //                mode: 'iframe', 
        //              //  mode: 'remote', 
        //                noCache: false 
        //            }, 
        //contentEl : Ext.DomHelper.append(document.body, {
        //    showMask: true, 
        //    tag : 'iframe',
        //    style : "border 0px none;scrollbar:true",
        //    src : url,
        //    height : "100%",
        //    width : "100%"
        //   }),

        resizable: false,
        html: '<iframe frameborder="0" width="100%" height="' + height + '" src="' + newurl + '"></iframe>'
    });
    win.show();
    // win.load(url);
}

function popwinForVisio(url, title, width, height) {
    Ext.useShims = true;
    var obj = parent.parent.parent.parent.parent.parent;
    win = new obj.Ext.Window({
        id: 'popwingy',
        title: "<image class='x-panel-inline-icon' src='../img/application.png'>" + title + "",
        layout: 'fit',
        width: width,
        height: height,
        // autoShow:true,
        closeAction: 'close',
        collapsible: false,
        draggable: true,
        plain: false,
        modal: true,
        Icon: "House",
        //        autoLoad: 
        //            { 
        //                showMask: true, 
        //                mode: 'iframe', 
        //              //  mode: 'remote', 
        //                noCache: false 
        //            }, 
        //contentEl : Ext.DomHelper.append(document.body, {
        //    showMask: true, 
        //    tag : 'iframe',
        //    style : "border 0px none;scrollbar:true",
        //    src : url,
        //    height : "100%",
        //    width : "100%"
        //   }),

        resizable: false,
        html: '<iframe frameborder="0" width="100%" height="' + height + '" src="' + url + '"></iframe>'
    });
    win.show();
    // win.load(url);
}

//**************************关闭弹出窗口*********************************//
function Closepopwin() {
    var pop = parent.Ext.getCmp('popwingy');
    pop.close();
}

function RefreshPopwin() {
    var pop = parent.Ext.getCmp('popwingy');
    pop.reload();
}

//关闭父窗体的上一级窗体弹出窗口
function Closepopwin2(winid) {
    var pop = parent.Ext.getCmp(winid);
    pop.close();
}

//关闭父窗体的上一级窗体的上一级窗体弹出窗口
function Closepopwin3(winid) {
    var pop = parent.parent.Ext.getCmp(winid);
    pop.close();
}

//**************************弹出窗口****************************
function popforwinTop(gridName, url, title, winWidth, winHeight, StringName, StringField, RowId, AttQryStr, flag, InObject) {

    var Str = "";
    var StrName = StringName.split(",");
    var StrField = StringField.split(",");

    if (flag == 1) {
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + StrField[i];
        }
    }
    if (flag == 2) {
        if (!gridName.hasSelection()) {
            Ext.Msg.alert("提示", "请选择记录!");
            return;
        }
        var record = gridName.selModel.getSelected();
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + escape(record.get(StrField[i]));
        }
    }
    if (flag == 3) {
        var record3 = gridName.store.data.items[RowId].data;
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + escape(record3[StrField[i]]);
        }
    }

    var NewUrl = url;
    if (Str != "") {
        NewUrl = NewUrl + "?" + Str;
        if (AttQryStr != "")
            NewUrl = NewUrl + "&" + AttQryStr;
    }
    else {
        if (AttQryStr != "")
            NewUrl = NewUrl + "?" + AttQryStr;
    }

    popTopwin(NewUrl, title, winWidth, winHeight, InObject);

}

function popforwin(gridName, url, title, winWidth, winHeight, StringName, StringField, RowId, AttQryStr, flag) {

    var Str = "";
    var StrName = StringName.split(",");
    var StrField = StringField.split(",");

    if (flag == 1) {
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + StrField[i];
        }
    }
    if (flag == 2) {
        if (!gridName.hasSelection()) {
            Ext.Msg.alert("提示", "请选择记录!");
            return;
        }
        var record = gridName.selModel.getSelected();
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + escape(record.get(StrField[i]));
        }
    }
    if (flag == 3) {
        var record3 = gridName.store.data.items[RowId].data;
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + escape(record3[StrField[i]]);
        }
    }

    var NewUrl = url;
    if (Str != "") {
        NewUrl = NewUrl + "?" + Str;
        if (AttQryStr != "")
            NewUrl = NewUrl + "&" + AttQryStr;
    }
    else {
        if (AttQryStr != "")
            NewUrl = NewUrl + "?" + AttQryStr;
    }

    popwin(NewUrl, title, winWidth, winHeight);

}

function popforwinParent(gridName, url, title, winWidth, winHeight, StringName, StringField, RowId, AttQryStr, flag) {

    var Str = "";
    var StrName = StringName.split(",");
    var StrField = StringField.split(",");

    if (flag == 1) {
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + StrField[i];
        }
    }
    if (flag == 2) {
        if (!gridName.hasSelection()) {
            Ext.Msg.alert("提示", "请选择记录!");
            return;
        }
        var record = gridName.selModel.getSelected();
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + record.get(StrField[i]);
        }
    }
    if (flag == 3) {
        var record3 = gridName.store.data.items[RowId].data;
        for (i = 0; i < StrName.length; i++) {
            if (i > 0)
                Str += "&";
            Str = Str + StrName[i] + "=" + record3[StrField[i]];
        }
    }

    var NewUrl = url;
    if (Str != "") {
        NewUrl = NewUrl + "?" + Str;
        if (AttQryStr != "")
            NewUrl = NewUrl + "&" + AttQryStr;
    }
    else {
        if (AttQryStr != "")
            NewUrl = NewUrl + "?" + AttQryStr;
    }

    popwinForParent(NewUrl, title, winWidth, winHeight);

}


//************************************************以上公共调用页面弹出、双击***************************************************/


//*************************************************以下为自定制函数********************************************************/
     


String.prototype.Trim = function() { return Trim(this); }
String.prototype.LTrim = function() { return LTrim(this); }
String.prototype.RTrim = function() { return RTrim(this); }


//此处为独立函数


function LTrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) != " " && str.charAt(i) != " ") break;
    }
    str = str.substring(i, str.length);
    return str;
}

function RTrim(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) != " " && str.charAt(i) != " ") break;
    }
    str = str.substring(0, i + 1);
    return str;
}

function Trim(str) {
    return LTrim(RTrim(str));
}



//***********************************************以上为自定制函数**********************************************/

//****************************************************批量验证、清空方法*********************************************************************//
//js清空页面extjs控件当前值

//pnl参数类型Panel
////js清空页面extjs控件当前值//pnl参数类型Panel
function ClearCtrlValues2(pnl,notClearReadOnly) {
    try {
        pnl.items.each(function(item, index, length) {
            //            alert(item.getXType() + ':' + item.id);
            switch (item.getXType()) {
                case 'panel':
                case 'container':
                    ClearCtrlValues2(item, notClearReadOnly);
                    break
                case "coolitemultifield":
                case "compositefield":
                    ClearCtrlValues3(item, notClearReadOnly);
                    break
                case 'coolitetriggercombo':
                case 'datefield':
                case 'timefield':
                case 'textarea':
                case 'textfield':
                case 'numberfield':
                case 'netdropdown':
                case 'nettrigger':
                case 'combo':
                case 'hidden':
                    if(!(notClearReadOnly && item.readOnly))
                        item.setValue('');
                    break
            }
        });
    } catch (e) {

    }
}

function ClearCtrlValues3(multiField, notClearReadOnly) {
    if (multiField.fields.length > 0) {
        for (var i = 0; i < multiField.fields.length; i++) {
            switch (multiField.fields[i].getXType()) {
                case 'coolitetriggercombo':
                case 'datefield':
                case 'timefield':
                case 'textarea':
                case 'textfield':
                    if (!(notClearReadOnly && imultiField.fields[i]))
                        multiField.fields[i].setValue('');
                    break
            }
        }
    }
}

//扩展Array的方法contains
Array.prototype.contains=function(item){
    for (var i = 0; i < this.length; i++) {
        if(this[i] ==item)
            return true;
    }
    return false;
};

function ClearCtrlValuesNoClear(pnl, noClearIDs) {
    try {
        pnl.items.each(function(item, index, length) {
            switch (item.getXType()) {
                case 'panel':
                case 'container':
                    ClearCtrlValuesNoClear(item, noClearIDs);
                    break
                case "coolitemultifield":
                case "compositefield":
                    ClearCtrlValues3(item);
                    break
                case 'coolitetriggercombo':
                case 'datefield':
                case 'timefield':
                case 'textarea':
                case 'textfield':
                case 'numberfield':
                case 'netdropdown':
                case 'nettrigger':
                case 'combo':
                case 'hidden':
                    if (noClearIDs == undefined || noClearIDs == null || noClearIDs.length == 0 || !noClearIDs.contains(item.id)) {
                        item.setValue('');
                    }
                    break;
            }
        });
    } catch (e) {

    }
}




//对allowBlank=false的Extjs控件检查值是否为空

//pnl参数类型Panel
function FieldEmptyCheck2(pnl, verifyTrim) {
    var result = true;
    try {
        pnl.items.each(function(item, index, length) {
            var xtype = item.getXType();
            switch (xtype) {
                case "container":
                case 'fieldset':
                case 'panel':
                case 'compositefield':
                    if (!FieldEmptyCheck2(item)) {
                        result = false;
                        return false;
                    }
                    break
                case "coolitemultifield":
                    if (FieldEmptyCheck3(item) == false) {
                        result = false;
                        return false;
                    }
                    break
                case "numberfield":
                    if (item.allowBlank == false) {
                        var value = item.getValue();
                        if (value === "") {
                            focusObj = item;
                            Ext.Msg.alert("系统提示", "[" + item.fieldLabel + "]不能为空！", FocusEL);
                            result = false;
                            return false;
                        }
                    }
                    break
                case 'coolitetriggercombo':
                case 'coolitetrigger':
                case 'datefield':
                case 'textarea':
                case 'textfield':
                case 'netdropdown':
                case 'nettrigger':
                    if (item.allowBlank == false) {
                        var val = verifyTrim ? item.getValue().trim() : item.getValue();
                        if (val == "") {
                            focusObj = item;
                            Ext.Msg.alert("系统提示", "[" + item.fieldLabel + "]不能为空！", FocusEL);
                            result = false;
                            return false;
                        }
                    }
                    break
                case 'combo':
                    if (item.allowBlank == false) {
                        if (item.getSelectedItem().text == item.emptyText || item.getValue() == "") {
                            focusObj = item;
                            Ext.Msg.alert("系统提示", "[" + item.fieldLabel + "]不能为空！", FocusEL);
                            result = false;
                            return false;
                        }
                    }
                default:
                    return result;
                    break;
            }
        });
    }
    catch (e) {

    }
    return result;
}


/**
 * 验证表单元素是否为空(vlue进行trim处理)
 * @param {object} pnl  要验证的FormPanel
 */
function FieldEmptyCheck2Trim(pnl) {
    return FieldEmptyCheck2(pnl, true);
}

function FieldEmptyCheck3(multiField) {
    var result = true;
    if (multiField.fields.length > 0) {
        for (var i = 0; i < multiField.fields.length; i++) {
            //                        alert(multiField.fields[i].getXType());
            switch (multiField.fields[i].getXType()) {
                case 'coolitetriggercombo':
                case 'datefield':
                case 'textarea':
                case 'textfield':
                case 'DropDownField':
                case 'ComboBox':
                case 'TriggerField':
                    if (multiField.fields[i].allowBlank == false) {
                        if (multiField.fields[i].getValue() == "") {
                            focusObj = multiField.fields[i];
                            Ext.Msg.alert("系统提示", "[" + multiField.fields[i].fieldLabel + "]不能为空！", FocusEL);
                            result = false;
                            return false;
                        }
                    }
                    break
            }
        }
    }

    if (result == true)
        return true;
    else
        return false;
}
//***********************************************批量验证、清空方法(结束)**********************************************/



//*****************************************树结构中针对复选框父/子节点选中时的打勾情况***************************/
//为主函数,在单击树节点的函数中调用
function checkNode(node) {
    uncheckParentNode(node);
    checkChildNodes(node, node.getUI().isChecked());
}

function uncheckParentNode(node) {
    if (node.parentNode != undefined) {
        var nodeArray = node.parentNode.childNodes;
        var checked = getcheckcount(node) == nodeArray.length;
        if (node.parentNode.getUI().checkbox != undefined) {
            node.parentNode.getUI().checkbox.checked = checked;
        }
        uncheckParentNode(node.parentNode);
    }
}

function checkChildNodes(node, checked) {
    var nodeArray = node.childNodes;
    for (var i = 0; i < nodeArray.length; i++) {
        if (nodeArray[i].getUI().checkbox != undefined)
            nodeArray[i].getUI().checkbox.checked = checked;
        if (nodeArray[i].hasChildNodes())
            checkChildNodes(nodeArray[i], checked);
    }
}

function getcheckcount(node) {
    var count = 0;
    var nodeArray = node.parentNode.childNodes;
    for (var i = 0; i < nodeArray.length; i++) {
        if (nodeArray[i].getUI().isChecked()) {
            count++;
        }
    }
    return count;
}
//*********************************************以上为树节点上有复选框时父子节点打勾情况的函数********************************/

///////////*******************************************格式化函数************************************************************//////////////////////

function FormatNumber(intInput, count) {
    //得到要精确的位数
    var c = 1;
    for (var i = 0; i < count; i++) {
        c += "0";
    }
    //将字符转化为数字
    c = parseInt(c);
    //精确数字
    var strInput = (Math.round(intInput.toString().replace(/,/g, "") * c) / c);
    //通过toFixed四舍五入
    //strInput = strInput.toFixed(count);
    return strInput;
}


//***************************格式化Grid日期显示格式为yyyy-mm-dd****************************
function FormatDate(value) {
    if (value != null) {
        var reDate = /\d{4}\-\d{2}\-\d{2}/gi;
        return value.match(reDate);
    }
}

//***************************格式化Grid数字显示格式****************************
function FormatNumbVal(val, digits) {
    if (val != null)
        return Number(val).toFixed(digits);
}

//***************************格式化Grid日期显示格式为yyyy-mm-dd****************************
function renderDate2(value) {
    if (value != null) {
        var reDate = /\d{4}\-\d{2}\-\d{2}/gi;
        return value.match(reDate);
    }
}

function renderDateTime2(value) {
    if (value == "") {
        return "";
    }
    if (value.indexOf('+') > 0) {
        value = value.substring(0, value.indexOf('+'));
    }
    if (value != null) {
        var reDate = /\d{4}\-\d{2}\-\d{2}/gi;
        var reTime = /\d{2}:\d{2}/gi;
        return value.match(reDate) + " " + value.match(reTime);
    }
}

function renderDateTime3(value) {
    if (value == "") {
        return "";
    }
    if (value.indexOf('+') > 0) {
        value = value.substring(0, value.indexOf('+'));
    }
    if (value != null) {
        var reDate = /\d{4}\-\d{2}\-\d{2}/gi;
        var reTime = /\d{2}:\d{2}:\d{2}/gi;
        return value.match(reDate) + " " + value.match(reTime);
    }
}

//*******************************************拼音码***************************************************/
//传入两个控件，例Getpinyin(#{exttxtf_Customer_Name},#{exttxtf_hz_py})
function Getpinyin(extname, extpy) {
    var value = extname.getValue();
    if (value != "") {
        Ext.net.DirectMethods.Getpinyin(value, {
            success: function(result) {
                extpy.setValue(result);
            },
            failure: function(errorMsg) {
                Ext.Msg.alert('Failure', errorMsg);
            }
        });
    }
}


//*****************************************查找用户相关js***********************************************/
//对用户分3种键值查找的情况调用，数字为卡号；字符为查询码；汉字为用户名
//示例，目前不认识从输入法输入英文字母的情况，参照Cust_Manage绑定
var iState = 0;
function SearchByWhere(e, extcombname, strWhere, stoname) {
    var key = e.getKey();
    if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
        extcombname.lastKey = key;
        extcombname.dqTask.delay(extcombname.queryDelay);
        var value = extcombname.getRawValue();
        if (value != '') {
            iState = 2;
            Ext.net.DirectMethods.BindUserComb(value, strWhere, stoname);
            extcombname.selectedIndex = -1;
        }
        else {
            if (key == 8 || key == 46) {
                iState = 1;
                Ext.net.DirectMethods.BindUserComb("", strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
        }

    }
}

function SearchUserByWhere(extcombname, strWhere, stoname) {
    var value = extcombname.getRawValue();
    if (value == "" && iState == 2) {
        Ext.net.DirectMethods.BindUserComb("", strWhere, stoname);
        iState = 1;
        extcombname.selectedIndex = -1;
    }
}

//供应商名称的模糊查询
function SearchSupplierByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindSupplierComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindSupplierComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }

        }
    }
    else {
        Ext.net.DirectMethods.BindSupplierComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//生产厂商名称的模糊查询
function SearchProducerByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindProducerComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindProducerComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }

        }
    }
    else {
        Ext.net.DirectMethods.BindProducerComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//合同编号名称的模糊查询
function SearchBidderByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindBidderComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindBidderComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }

        }
    }
    else {
        Ext.net.DirectMethods.BindBidderComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//物品名称的模糊查询
function SearchMatByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindMatComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindMatComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }

        }
    }
    else {
        Ext.net.DirectMethods.BindMatComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//物品名称暂存库的模糊查询
function SearchMatZcByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindMatZcComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindMatZcComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }

        }
    }
    else {
        Ext.net.DirectMethods.BindMatZcComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//物品名称中心库的模糊查询
function SearchMatKfByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindMatKfComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindMatKfComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }

        }
    }
    else {
        Ext.net.DirectMethods.BindMatKfComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//下账物品的模糊查询
function SearchStoreKfByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindStoreKfComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindStoreKfComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }
        }
    }
    else {
        Ext.net.DirectMethods.BindStoreKfComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//不可收费医材下账物品的模糊查询
function SearchStoreKfNoPayByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindStoreKfNoPayComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindStoreKfNoPayComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }
        }
    }
    else {
        Ext.net.DirectMethods.BindStoreKfNoPayComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}

//模糊查询
function SearchMaterialByWhere(e, extcombname, field, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindMaterialComb(value, field, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindMaterialComb("", field, stoname);
                    extcombname.selectedIndex = -1;
                }
            }
        }
    }
    else {
        Ext.net.DirectMethods.BindMaterialComb(extcombname.getSelectedItem().text, field, stoname);
        extcombname.selectedIndex = -1;
    }
}

function SearchStoreroomByWhere(e, extcombname, strWhere, stoname) {
    if (e != null) {
        var key = e.getKey();
        if (extcombname.editable !== false && (key == e.BACKSPACE || !e.isSpecialKey())) {
            extcombname.lastKey = key;
            extcombname.dqTask.delay(extcombname.queryDelay);
            var value = extcombname.getRawValue();
            if (value != '') {
                iState = 2;
                Ext.net.DirectMethods.BindStoreroomComb(value, strWhere, stoname);
                extcombname.selectedIndex = -1;
            }
            else {
                if (key == 8 || key == 46) {
                    iState = 1;
                    Ext.net.DirectMethods.BindStoreroomComb("", strWhere, stoname);
                    extcombname.selectedIndex = -1;
                }
            }
        }
    }
    else {
        Ext.net.DirectMethods.BindStoreroomComb(extcombname.getSelectedItem().text, strWhere, stoname);
        extcombname.selectedIndex = -1;
    }
}
////////////////***************************发送流程时弹出选择对象页面后到父页面要执行调用的JS方法****************************///////////////////
function GetValueSendFlow(result) {
    Ext.net.DirectMethods.GetValueSendMove(result, {
        success: function(result) {
            closeCurrTab();
        },
        failure: function(response) {
            alert(response);
        }
    });
}


//////////////**************************GridPanel相关Js方法*****************************************************************//////////////////
///ie,表格内容选中 方法调用在AfterRender
var EnableTextSelection = function(grid) {
    if (Ext.isIE) {
        grid.store.on("load", function() {
            var elems = Ext.DomQuery.select("div[unselectable=on]", grid.dom);
            for (var i = 0, len = elems.length; i < len; i++) {
                elems[i].unselectable = "off";
            }
        });
    }
};

///判断Grid是否选中一条记录

function SelCount_Grd(GrdPanel) {
    var count = GrdPanel.getSelectionModel().selections.length;
    if (count == 0) {
        Ext.Msg.alert('系统提示', '请先选择一个记录！');
        return false;
    }
    else
        return true;
}

//弹出窗口GridPanel根据一个字段值串选中相应行

//FieldName,字段名称
//idString,字段名称对应字段值串
//GridPanelName,GridPanel名称
function GridPanelSeledCheck(idString, GridPanelName, FieldName) {
    var selID = idString.split(',');
    var grid = Ext.getCmp(GridPanelName);
    grid.selModel.clearSelections();
    var gridData = grid.getStore().getRange();
    for (var j = 0; j < gridData.length; j++) {
        for (var i = 0; i < selID.length; i++) {
            if (String(gridData[j].data[FieldName]) == selID[i]) {
                grid.selModel.selectRow(j, true);
            }
        }
    }
}

//*********************************************GridPanel行定位的函数********************************/
//GridName,GridPanel名称
//FieldName,字段名称
//FindValue,定位值

function PositionRecord(GridName, FieldName, FindValue) {

    if (Trim(FindValue) == "")
        return false;
    var nLength = GridName.store.data.items.length;
    for (i = 0; i < nLength; i++) {
        if (FindValue == GridName.store.data.items[i].data[FieldName]) {
            break;
        }
    }
    GridName.selModel.clearSelections();
    if (i < nLength) {
        GridName.getView().focusRow(i);
        GridName.selModel.selectRow(i, true);
    }
}

////////////**************************以上为GridPanel相关Js方法***********************************************************////////////////


//*********************************************js定位的函数********************************/

function GetWebUrl() {
    var url = "";
    url = window.location.protocol + "//" + window.location.host;
    url += "/" + window.location.pathname.split("/")[1];
    return url;
}

BLANK_IMAGE_URL = "../extjs/resources/images/default/s.gif";


/*
*   定义一个相乘的函数
*   浮点数乘以整数，保证结果精度正常
*/
Math.multiply = function(number, count) {
    var result = 0;
    if (number.toString().indexOf('.') < 0) {
        result = number * count;
    } else {
        var len = number.toString().split('.')[1].length;
        var result = Math.round(number * count * Math.pow(10, len)) / Math.pow(10, len);
    }
    return result;
};


  